import yaml
import re
import sys

# 定义文件路径
file_path = 'app/static/uploads/products/纸尿裤_a2a26a5b/analysis_result.yaml'

try:
    # 读取文件内容
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()
    
    # 替换Python特有的元组标记
    content = re.sub(r'- !!python/tuple', r'- ', content)
    
    # 写回文件
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(content)
    
    print("成功修复YAML文件!")
    
    # 测试是否可以加载
    with open(file_path, 'r', encoding='utf-8') as file:
        data = yaml.safe_load(file)
    print("成功加载修复后的YAML文件!")
    
except Exception as e:
    print(f"修复YAML文件失败: {str(e)}")
    sys.exit(1) 